<div class="products form">
<?php echo $this->ExtendedForm->create('Product', array('class' => 'form-horizontal', 'novalidate' => 'novalidate'));?>
    <fieldset>
        <legend><?php echo __d('admin', 'Edit Product'); ?></legend>
        <div class="form-group row">
			<div class="col-sm-2">
				<label for="language">Language</label>
				<select name="language" id="language" class="form-control">
					<option value="vietnam">VietNam</option>
					<option value="english">English</option>
				</select>
			</div>
		</div>
	<?php
        if(isset($this->request->params['named']['brand_id'])) echo '<div style="display: none;">';
		echo $this->ExtendedForm->input('brand_id', array_merge(array('id'=> 'brand','label' => __d('admin', 'Brand')), array('options' => $productBrandsSelect, 'empty' => '- ' . __d('admin', 'Choose Brand') . ' -')));
		if(isset($this->request->params['named']['brand_id'])) echo '</div>';
        
		if(isset($this->request->params['named']['product_id'])) echo '<div style="display: none;">';
		echo $this->ExtendedForm->input('product_id', array_merge(array('label' => __d('admin', 'Product'))));
		if(isset($this->request->params['named']['product_id'])) echo '</div>';

        echo '<div id="category">';
		if(isset($this->request->params['named']['product_category_id'])) echo '<div style="display: none;">';
		echo $this->ExtendedForm->input('product_category_id', array_merge(array('label' => __d('admin', 'Product Category')), array('options' => $productCategoriesSelect, 'empty' => '- ' . __d('admin', 'Choose Category') . ' -')));
		if(isset($this->request->params['named']['product_category_id'])) echo '</div>';
		echo '</div>';
        
		if(isset($this->request->params['named']['code'])) echo '<div style="display: none;">';
		echo $this->ExtendedForm->input('code', array_merge(array('label' => __d('admin', 'Code'))));
		if(isset($this->request->params['named']['code'])) echo '</div>';
        
        if(isset($this->request->params['named']['alias'])) echo '<div style="display: none;">';
		echo $this->ExtendedForm->input('alias', array_merge(array('label' => __d('admin', 'Alias Url'))));
		if(isset($this->request->params['named']['alias'])) echo '</div>';
	?>
	<div class="area-language" id="text-vietnam">
	<?php
		if(isset($this->request->params['named']['name'])) echo '<div style="display: none;">';
		echo $this->ExtendedForm->input('name', array_merge(array('label' => __d('admin', 'Name'))));
		if(isset($this->request->params['named']['name'])) echo '</div>';

		if(isset($this->request->params['named']['description'])) echo '<div style="display: none;">';
		echo $this->Form->input('Product.description', array_merge(array('type' => 'textarea', 'label' => __d('admin', 'Short Des'), 'class' => 'form-control', 'div' => 'form-group row', 'before' => '<div class="col-sm-10">', 'after' => '</div>')));
		if(isset($this->request->params['named']['short_des'])) echo '</div>';
	?>
	</div>
    <div class="area-language" id="text-english" style="display:none">
	<?php	
		if(isset($this->request->params['named']['name_en'])) echo '<div style="display: none;">';
		echo $this->ExtendedForm->input('name_en', array_merge(array('label' => __d('admin', 'Name En'))));
		if(isset($this->request->params['named']['name_en'])) echo '</div>';
		
		if(isset($this->request->params['named']['description_en'])) echo '<div style="display: none;">';
		echo $this->Form->input('Product.description_en', array_merge(array('type' => 'textarea', 'label' => __d('admin', 'Short Des En'), 'class' => 'form-control', 'div' => 'form-group row', 'before' => '<div class="col-sm-10">', 'after' => '</div>')));
		if(isset($this->request->params['named']['description_en'])) echo '</div>';
	?>
	</div>
	<?php		
		if(isset($this->request->params['named']['image'])) echo '<div style="display: none;">';
		echo $this->ExtendedForm->input('image', array_merge(array('type' => 'image', 'label' => __d('admin', 'Image (900x900)'))));
		if(isset($this->request->params['named']['image'])) echo '</div>';
	?>
    </fieldset>
	<div class="row">
		<div class="col-sm-6">Elements product Vn</div>
		<div class="col-sm-6">Elements product En</div>
	</div>
	<div id="product-detail">
		<?php foreach($productDetail as $detail) :?>
			<?php echo $this->element('AdminProducts/detail', array('element' => $detail['ProductDetail']));?>
		<?php endforeach;?>
	</div>
	<div align="right" class="col-sm-11"><i class="glyphicon glyphicon-plus-sign" id="add-detail" style="cursor:pointer"></i> More element</div>
	<br>
<?php echo $this->ExtendedForm->end(array('label' => __d('admin', 'Save Product'), 'class' => 'btn btn-primary', 'div' => false, 'before' => '<div class="control-group"><div class="controls">', 'after' => "\n" . $this->Html->link(__d('admin', 'Cancel'), $redirectUrl, array('class' => 'btn btn-default')) . '</div></div>'));?>
</div>
<div style="display:none" id="step-detail"><?php echo $this->element('AdminProducts/detail');?></div>
<script type="text/javascript">
$(document).ready(function () {
	$("#add-detail").click(function () { 
		$('#product-detail').append($('#step-detail').html());
	});
	
	$("#product-detail").on("click", ".glyphicon-minus-sign", function(){
		var _this = $(this);
		var id = $(this).attr('rel');
		$.ajax({
			url: '/admin/products/deleteProductEmelent',
			data: {'id': id},
			type: 'post',
			success: function(response) {
				if(response) _this.parent().parent().remove();
			}
		});
	});
    
    $('#brand').change(function(){
        var brandId = $(this).val();
        $.ajax({
			url: '/admin/products/changeBrand',
			data: {'brandId': brandId},
			type: 'post',
			success: function(response) {
				if(response) $('#category').html(response);
			}
		});
    });
});
</script>